package com.junci.mtest.model.http;



import com.junci.mtest.model.Constants;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 尼莫
 * 这是~
 */
public class OtherInterfaceRetrofit {
    private static Retrofit retrofit;

    public static Retrofit getRetrofit() {

        if (retrofit == null) {
            MyHttpLoggingInterceptor loggingInterceptor = new MyHttpLoggingInterceptor(new MyHttpLoggingInterceptor.Logger() {
                @Override
                public void log(String message) {
//                    if (LogUtil.isLog()) {
//                        LogUtil.s("  OkHttp网络请求日志：" + message);
////                        LogUtil.writeErrorToFile("  OkHttp网络请求日志："+message);
//                    }
                }
            }).setLevel(MyHttpLoggingInterceptor.Level.BODY);
            synchronized (OtherInterfaceRetrofit.class) {
                if (retrofit == null) {
                    retrofit = new Retrofit.Builder()
                            .baseUrl(Constants.BASE_URL)//Constants.BASE_URL
                            .addConverterFactory(GsonConverterFactory.create())
                            .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                            .client(new OkHttpClient.Builder()
                                    .connectTimeout(5, TimeUnit.SECONDS)
                                    .writeTimeout(10, TimeUnit.SECONDS)
                                    .readTimeout(10, TimeUnit.SECONDS)
                                    .addInterceptor(loggingInterceptor)
                                    .build()).build();
                }
            }
        }
        return retrofit;
    }
}
